<template>
  <el-dialog v-model="centerDialogVisible" title="Tips" width="500" destroy-on-close>
    <span> {{ judgment(type.status) }} </span>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="confirm"> 确定 </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref } from 'vue'

const centerDialogVisible = ref(false)
const type = ref({
  status: null,
  id: null
})

const emit = defineEmits(['delete'])

const judgment = (status) => {
  if (status === 1) {
    //自己的文章
    return '确定要删除这篇文章吗？'
  } else if (status === 2) {
    // 删除收藏的文章
    return '确定要取消收藏这篇文章吗？'
  } else if (status === 3) {
    return '确定要取消点赞吗？'
  }
}

const confirm = () => {
  emit('delete', type.value.status, type.value.id)
  centerDialogVisible.value = false
  type.value = {
    status: null,
    id: null
  }
}

const open = (status, id) => {
  console.log('收到了', status, id)

  centerDialogVisible.value = true
  type.value.status = status
  type.value.id = id
}
defineExpose({
  open
})
</script>
